package com.axisdesign.client;

import com.google.gwt.user.client.ui.ClickListener;
import com.google.gwt.user.client.ui.HorizontalPanel;
import com.google.gwt.user.client.ui.Image;
import com.google.gwt.user.client.ui.VerticalPanel;
import com.google.gwt.user.client.ui.Widget;

public class SubContentRightPanel extends VerticalPanel {
	final int menuID;
	int typeStatus;
	String name;
	
	HorizontalPanel contentTopPanel[];
	VerticalPanel contentTopImagePanel[];
	VerticalPanel contentTopTypePanel;
	
	Image contentTopImage[];
	Image contentTopTypeImageTop;
	FlipImage contentTopTypeImage[];
	Image contentBottomImage[];
	
	public SubContentRightPanel(String _name,int _id,int _typeStatus) {
		name=_name;
		menuID=_id;
		
		contentTopPanel =  new HorizontalPanel[SubContentPanel.typeImage];
		contentTopImagePanel = new VerticalPanel[SubContentPanel.typeImage];
		contentTopImage = new Image[SubContentPanel.typeImage];
		contentTopTypePanel = new VerticalPanel();
		contentTopTypeImage = new FlipImage[SubContentPanel.typeImage];
		contentBottomImage = new Image[SubContentPanel.typeImage];
		
		init(_typeStatus);
	}
	
	private void init(int _typeStatus) {
		queueTypeImage();		
		queue(_typeStatus);
		
		for(int i=0; i<SubContentPanel.typeImage; i++) {
			final int type = i;
			contentTopTypeImage[i].addClickListener(new ClickListener() {public void onClick(Widget sender) {queue(type);}});
		}
	}
	
	public void queue(int _typeStatus) {
		typeStatus = _typeStatus;
		if(contentTopPanel[typeStatus]==null) contentTopPanel[typeStatus] = new HorizontalPanel();
		if(contentTopImagePanel[typeStatus]==null) contentTopImagePanel[typeStatus] = new VerticalPanel();
		
		
		if(contentTopImage[typeStatus]==null) {
			contentTopImage[typeStatus] = new Image("images/mainFrame/content/subContent/"+name+"/"+menuID+"/"+typeStatus+"/contenttopimage.png");
		}

		contentTopPanel[typeStatus].add(contentTopImage[typeStatus]);
		contentTopPanel[typeStatus].add(contentTopTypePanel);
		
		if(contentBottomImage[typeStatus]==null) {
			contentBottomImage[typeStatus] = new Image("images/mainFrame/content/subContent/"+name+"/"+menuID+"/"+typeStatus+"/contentbottomimage.png");
		}
		
		clear();
		queueTypeImage();
		add(contentTopPanel[typeStatus]);
		add(contentBottomImage[typeStatus]);
	}
	
	private void queueTypeImage() {
		if(contentTopTypeImageTop==null) {
			contentTopTypeImageTop = new Image("images/mainFrame/content/subContent/"+name+"/"+menuID+"/contenttoptypeimagetop.png");
			contentTopTypePanel.add(contentTopTypeImageTop);
		}
		
		for(int i=0; i<SubContentPanel.typeImage; i++) {
			if(contentTopTypeImage[i]==null) {
				contentTopTypeImage[i] = new FlipImage(
					new PNGImage2("images/mainFrame/content/subContent/"+name+"/"+menuID+"/"+i+"/contenttoptypeimage_a.png",108,36)
					,new PNGImage2("images/mainFrame/content/subContent/"+name+"/"+menuID+"/"+i+"/contenttoptypeimage_b.png",108,36)
					,false);
				contentTopTypePanel.add(contentTopTypeImage[i]);
			}
			contentTopTypeImage[i].setImage1Default((typeStatus==i)?false:true);
		}
	}
	
	public int getTypeStatus() {return typeStatus;}
}
